# -*- coding: utf-8 -*-
import maya.cmds as cmds
class Motion_capture():
    def Data_window(self):
        cmds.window(title = u"匹配数据"  )
        cmds.columnLayout( columnAttach=('both', 5), rowSpacing=10, columnWidth=250 )
        cmds.button(l = u'设置角色',command = lambda *args:self.CharacterSet())
        cmds.button(l = u'烘焙角色',command = lambda *args:self.bake_Character())
        cmds.showWindow()
    def CharacterSet(self):
        if len(cmds.ls (sl=1)) ==0:
             cmds.error( u"请选择角色" )
        self.select_mod = cmds.ls (sl=1)[0]
        self.Namespace  =self.select_mod.split(":")[0]
        cmds.parentConstraint (self.Namespace + ":FKAnkle_R",self.Namespace + ":IKLeg_R",mo=1,weight =1)
        cmds.parentConstraint (self.Namespace + ":FKAnkle_L",self.Namespace + ":IKLeg_L",mo=1,weight =1)
        
        cmds.pointConstraint (self.Namespace + ":FKKnee_R",self.Namespace + ":PoleLeg_R",offset=[0,0,0],weight =1)
        cmds.pointConstraint (self.Namespace + ":FKKnee_L",self.Namespace + ":PoleLeg_L",offset=[0,0,0],weight =1)
        
        cmds.parentConstraint (self.Namespace + ":FKCup_R",self.Namespace + ":IKArm_R",mo=1,weight =1)
        cmds.parentConstraint (self.Namespace + ":FKCup_L",self.Namespace + ":IKArm_L",mo=1,weight =1)
        
        cmds.pointConstraint (self.Namespace + ":FKElbow_R",self.Namespace + ":PoleArm_R",offset=[0,0,0],weight =1)
        cmds.pointConstraint (self.Namespace + ":FKElbow_L",self.Namespace + ":PoleArm_L",offset=[0,0,0],weight =1)
        cmds.warning( u"角色设置成功" )
    def bake_Character(self):
        self.select_Cur =[]
        Cur = ['FKHead_M',"IKToes_L","IKToes_R",'RootX_M','FKRootPart1_M','FKSpine1_M','FKChest_M','FKShoulder_R','FKElbow_R','FKWrist_R','FKShoulder_L','FKElbow_L','FKWrist_L','FKNeck_M','FKNeck_M','FKScapula_R','FKScapula_L','FKHip_R','FKKnee_R','FKAnkle_R','FKHip_L','FKKnee_L','FKAnkle_L','IKLeg_R','PoleLeg_R','IKLeg_L','PoleLeg_L','IKArm_R','PoleArm_R','IKArm_L','PoleArm_L']
        for i in Cur:
            self.select_Cur.append(self.Namespace + ":" + i)
        selectBakeCur = cmds.ls (self.select_Cur)
        star = cmds.playbackOptions (q = 1,min=1 )
        end = cmds.playbackOptions (q = 1,max=1 )
        cmds.bakeResults(selectBakeCur,t=(star,end),simulation=True)
        
#Motion_capture().Data_window()
        
    


